#include <QCoreApplication>
#include <QMetaObject>
#include "description.h"
#include "operation.h"
#include "device.h"
#include "delay.h"
#include "controlled.h"
#include "movejoint.h"
#include "rs232.h"
#include "ethernet.h"
#include "snap.h"
#include <QHash>
#include <QFile>
#include <QXmlStreamWriter>
#include "objectfactory.h"

int writexml() {
    Description desc;
    // Devices
    Device* rs232 = (Device*)ObjectFactory::createObject("RS232");
    rs232->setStrID("1");
    Device* ethernet = (Device*)ObjectFactory::createObject("Ethernet");
    ethernet->setStrID("2");

    desc.AddDevice(rs232);
    desc.AddDevice(ethernet);

    Operation* movejoint = (Operation*)ObjectFactory::createObject("MoveJoint");
    movejoint->setStrDeviceID("2");
    Operation* delay = (Operation*)ObjectFactory::createObject("Delay");
    Operation* controlled = (Operation*)ObjectFactory::createObject("ControlLED");
    controlled->setStrDeviceID("1");

    Step* step1 = (Step*)ObjectFactory::createObject("Step");
    step1->setStrID("1");
    step1->AddOperation(delay);
    step1->AddOperation(controlled);
    step1->AddOperation(movejoint);
    desc.AddStep(step1);

    desc.writeXML("D:/description.xml");

    return 0;
}

int readxml(){
    Description desc;
    desc.ReadXML("D:/description.xml");

    desc.run();
}


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    //
    ObjectFactory::registerClass<Delay>();
    ObjectFactory::registerClass<ControlLED>();
    ObjectFactory::registerClass<MoveJoint>();
    ObjectFactory::registerClass<RS232>();
    ObjectFactory::registerClass<Ethernet>();
    ObjectFactory::registerClass<Step>();
    ObjectFactory::registerClass<Snap>();

    readxml();

    return a.exec();
}
